package com.spring.utils;

import java.lang.reflect.Method;

public class BeanUtil {


    /**
     * 实例化一个class
     * @param <T>
     * @param clazz Person.class
     * @return
     */
    public static <T> T instanceClass(Class<T> clazz){
        if(!clazz.isInterface()){
            try {
                return clazz.newInstance();
            } catch (InstantiationException e) {
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        }
        return null;
    }

    /**
     * 获取Class
     * @param classPath
     * @return
     */
    public static Class<?> getClass(String classPath){
        try {
            Class<?> aClass = Thread.currentThread().getContextClassLoader().loadClass(classPath);
            return aClass;
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 获取method 对象
     * @param name
     * @param aClass
     * @return
     */
    public static Method getMethod(String name,Class aClass){
        try {
            Method method = aClass.getMethod(name);
            return method;
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        }
        return null;
    }
}
